package com.cpj.bsyyzx.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cpj.bsyyzx.entity.Meals;
import com.cpj.bsyyzx.service.IMealsService;
import com.cpj.bsyyzx.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 五个臭皮匠
 * @since 2021-04-27
 */
@RestController
@RequestMapping("/meals")
public class MealsController {
    @Autowired
    IMealsService mealsService;

    @RequestMapping("list")
    CommonResult list(ModelMap map, Page page, @ModelAttribute("meals") Meals meals) {
        page.setSize(5);
        page = mealsService.pageList(page, meals);
        return CommonResult.success(page);
    }

    @RequestMapping("save")
    CommonResult save(Meals meals) {
        return CommonResult.success(mealsService.saveOrUpdate(meals));
    }

    @RequestMapping("getById")
    CommonResult getById(Integer id){
        return CommonResult.success(mealsService.getById(id));
    }

    @RequestMapping("delete")
    public CommonResult delete(Integer mealsId){
        boolean success=mealsService.removeById(mealsId);
        return CommonResult.success(success);
    }
}
